import processing.serial.*; Serial myPort; void setup() { size(300, 300); // Set the size of the canvas myPort = new Serial(this, "COM6", 9600); // Open the serial port myPort.bufferUntil('\n'); // Wait for a newline character } void draw() { // Draw the canvas background(255); rectMode(CENTER); rect(width / 2, height / 2, 100, 100); // Draw a square representing the LED // Check for mouse click if (mousePressed && (mouseButton == LEFT)) { myPort.write('1'); // Send '1' to turn on the LED } else if (mousePressed && (mouseButton == RIGHT)) { myPort.write('0'); // Send '0' to turn off the LED } } void mouseDragged() { myPort.write('3'); } void keyPressed() { myPort.write('2'); }